//
//  pictureDetailViewController.m
//  唧歪
//
//  Created by ZC on 15/7/20.
//  Copyright (c) 2015年 MWJ. All rights reserved.
//

#import "pictureDetailViewController.h"
#import "AppDelegate.h"
#import "postPic.h"
#import "picTableViewCell.h"

@interface pictureDetailViewController (){
    AppDelegate *app;
    NSMutableArray *array;
}

@end

@implementation pictureDetailViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationItem.title=@"所有图片";
    array = [NSMutableArray array];
    app = (AppDelegate *)[[UIApplication sharedApplication]delegate];
    for (int i=0;i<app.appimageArray.count; i+=3) {
        postPic *pp =[[postPic alloc]init];
        NSDictionary *dic = app.appimageArray[i];
        pp.photo1 =[dic objectForKey:@"image_path"];
        
        if (i+1<app.appimageArray.count) {
            NSDictionary *dic2 = app.appimageArray[i+1];
            pp.photo2 =[dic2 objectForKey:@"image_path"];
        }
        if(i+2<app.appimageArray.count){
            NSDictionary *dic3 = app.appimageArray[i+2];
            pp.photo3 =[dic3 objectForKey:@"image_path"];
        }
        [array addObject:pp];
    }

}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return [array count];
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 100;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    UINib *nib=[UINib nibWithNibName:@"picTableViewCell" bundle:nil];
    [_tableview registerNib:nib forCellReuseIdentifier:@"Cell"];
    static NSString *CellIdentifier = @"Cell";
    picTableViewCell *cell = [_tableview dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[picTableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
    }
//    cell.delegate=self;
    cell.tag = [indexPath row] + 100;
    postPic *pp = [array objectAtIndex:[indexPath row]];
    NSURL *url = [NSURL URLWithString:pp.photo1];
    cell.photoimage1.image = [UIImage imageWithData:[NSData dataWithContentsOfURL:url]];
    NSURL *url1 = [NSURL URLWithString:pp.photo2];
    cell.photoimage2.image = [UIImage imageWithData:[NSData dataWithContentsOfURL:url1]];
    NSURL *url2 = [NSURL URLWithString:pp.photo3];
    cell.photoimage3.image = [UIImage imageWithData:[NSData dataWithContentsOfURL:url2]];
//    cell.backgroundColor = [UIColor colorWithRed:233/255.0 green:240/255.0 blue:189/255.0 alpha:1];
    return cell;
    
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    
}


@end
